/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.synjones.pay.bank.wisedu.bean;

import com.synjones.pay.bank.wisedu.helper.WisPayHelper;
import com.synjones.pay.bank.wisedu.service.WisBankJumpImpl;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.security.NoSuchAlgorithmException;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * @author liubinqiang
 * @date 2017-5-20 14:00:29
 * @version V1.0
 * @desc 金智支付请求bean
 */
public class WiseduPayReqBean {

    private String sign;
    private String sysId;
    private String itemId;
    private String objId;
    private String otherId;
    private String objName;
    private String amount;
    private String remove;
    private String returnType;
    private String autoSubmit;
    private String specialValue;
    private String returnURL;

    public Map<String, String> getReqMap() {
        Map<String, String> reqMap = new HashMap<>();
        reqMap.put("sign", sign);
        reqMap.put("sysId", sysId);
        reqMap.put("itemId", itemId);
        reqMap.put("objId", objId);
        reqMap.put("otherId", otherId);
        reqMap.put("objName", objName);
        reqMap.put("amount", amount);
        reqMap.put("remove", remove);
        reqMap.put("returnType", returnType);
        reqMap.put("autoSubmit", autoSubmit);
        reqMap.put("specialValue", specialValue);
        reqMap.put("returnURL", returnURL);
        return reqMap;
    }

    public String genSign(String sysCert) {
        String firstSC = sysCert.charAt(0) + "";
        String[] signSource = new String[]{
            firstSC, sysId, firstSC, itemId, firstSC, objId, firstSC, otherId, firstSC, objName,
            firstSC, amount, firstSC, firstSC, "data", firstSC, specialValue, firstSC, returnURL,
            sysCert
        };
        String sign = "";
        try {
            sign = WisPayHelper.createSignString(signSource);
        } catch (UnsupportedEncodingException ex) {
            Logger.getLogger(WisBankJumpImpl.class.getName()).log(Level.SEVERE, null, ex);
        } catch (NoSuchAlgorithmException ex) {
            Logger.getLogger(WisBankJumpImpl.class.getName()).log(Level.SEVERE, null, ex);
        }
        return sign;
    }

    public String genPara(String sysCert) {
        StringBuffer params = new StringBuffer();
        params.append("sign=").append(genSign(sysCert));
        params.append("&sysId=").append(sysId);
        params.append("&itemId=").append(itemId);
        params.append("&objId=").append(objId);
        try {
            params.append("&objName=").append(URLEncoder.encode(objName, "UTF-8"));
            params.append("&otherId=").append(URLEncoder.encode(otherId, "UTF-8"));
            params.append("&specialValue=").append(URLEncoder.encode(specialValue, "UTF-8"));
            params.append("&returnURL=").append(URLEncoder.encode(returnURL, "UTF-8"));
        } catch (UnsupportedEncodingException ex) {
            Logger.getLogger(WisBankJumpImpl.class.getName()).log(Level.SEVERE, null, ex);
        }
        params.append("&amount=").append(amount);
        params.append("&returnType=").append("data");
        return params.toString();
    }

    /**
     * @return the sign
     */
    public String getSign() {
        return sign;
    }

    /**
     * @param sign the sign to set
     */
    public void setSign(String sign) {
        this.sign = sign;
    }

    /**
     * @return the sysId
     */
    public String getSysId() {
        return sysId;
    }

    /**
     * @param sysId the sysId to set
     */
    public void setSysId(String sysId) {
        this.sysId = sysId;
    }

    /**
     * @return the itemId
     */
    public String getItemId() {
        return itemId;
    }

    /**
     * @param itemId the itemId to set
     */
    public void setItemId(String itemId) {
        this.itemId = itemId;
    }

    /**
     * @return the objId
     */
    public String getObjId() {
        return objId;
    }

    /**
     * @param objId the objId to set
     */
    public void setObjId(String objId) {
        this.objId = objId;
    }

    /**
     * @return the otherId
     */
    public String getOtherId() {
        return otherId;
    }

    /**
     * @param otherId the otherId to set
     */
    public void setOtherId(String otherId) {
        this.otherId = otherId;
    }

    /**
     * @return the objName
     */
    public String getObjName() {
        return objName;
    }

    /**
     * @param objName the objName to set
     */
    public void setObjName(String objName) {
        this.objName = objName;
    }

    /**
     * @return the amount
     */
    public String getAmount() {
        return amount;
    }

    /**
     * @param amount the amount to set
     */
    public void setAmount(String amount) {
        this.amount = amount;
    }

    /**
     * @return the remove
     */
    public String getRemove() {
        return remove;
    }

    /**
     * @param remove the remove to set
     */
    public void setRemove(String remove) {
        this.remove = remove;
    }

    /**
     * @return the returnType
     */
    public String getReturnType() {
        return returnType;
    }

    /**
     * @param returnType the returnType to set
     */
    public void setReturnType(String returnType) {
        this.returnType = returnType;
    }

    /**
     * @return the autoSubmit
     */
    public String getAutoSubmit() {
        return autoSubmit;
    }

    /**
     * @param autoSubmit the autoSubmit to set
     */
    public void setAutoSubmit(String autoSubmit) {
        this.autoSubmit = autoSubmit;
    }

    /**
     * @return the specialValue
     */
    public String getSpecialValue() {
        return specialValue;
    }

    /**
     * @param specialValue the specialValue to set
     */
    public void setSpecialValue(String specialValue) {
        this.specialValue = specialValue;
    }

    /**
     * @return the returnURL
     */
    public String getReturnURL() {
        return returnURL;
    }

    /**
     * @param returnURL the returnURL to set
     */
    public void setReturnURL(String returnURL) {
        this.returnURL = returnURL;
    }

}
